package real.lang;

import real.lang.reflect.RealType;

public abstract class RealSet extends RealObject {
	
	public RealSet(RealType type) {
		super(type);
	}

	public boolean isFinite() {
		return this instanceof FiniteSet; 
	}	
	
	/**
	 * Set Equality check consists of two steps: 
	 * 1) check logical symbolic equivalence, that is current instance can be of some 
	 * descendant class that is an infinite set like natural numbers. In this case we need 
	 * to state equality without any enumeration but on logical level.  
	 * 2) if set is finite we need to check equivalence by enumeration ( @see FiniteSet). 
	 * @throws RealLangException 
	 * 
	 **/
	public boolean equals(RealSet set) {		
		if (this.isFinite() != set.isFinite()) return false;		
		if (this.isFinite())
		{
			// finite (enumerative) equivalence
			FiniteSet A = (FiniteSet)this;
			FiniteSet B = (FiniteSet)set;
			return (A == B);
		}
		else 
		{
			// type (symbolic) equivalence
			return (this.getRealType()== set.getRealType());
		}		
	}
		
}
